<template>
	<div>
		<el-dialog :title="$t('action.update')" width="70%" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Minus_uid')" prop="uid">
							<el-input v-model="form.uid" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Minus_uid')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Minus_number')" prop="number">
							<el-input v-model="form.number" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Minus_number')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Minus_remark')" prop="remark">
							<el-input v-model="form.remark" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Minus_remark')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.Minus_status')" prop="status">
                            <el-select style="width:100%" v-model="form.status" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="申请" :value="0"></el-option>
                                <el-option key="1"  label="批准" :value="1"></el-option>
                                <el-option key="2"  label="驳回" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Minus_type')" prop="type">
							<el-select style="width:100%" v-model="form.type" filterable clearable :placeholder="$t('system.pleaseSelect')">
								<el-option v-for="(item,i) in types" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				 </el-row>
	 	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Minus_approved_by')" prop="approved_by">
							<el-input v-model="form.approved_by" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Minus_approved_by')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Minus_approve_time')" prop="approve_time">
							<el-date-picker type="date"   v-model="form.approve_time" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.Minus_approve_time')})"></el-date-picker>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Minus_caller')" prop="caller">
							<el-select style="width:100%" v-model="form.caller" filterable clearable :placeholder="$t('system.pleaseSelect')">
								<el-option v-for="(item,i) in callers" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				 </el-row>
				</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">{{$t('system.confirm')}}</span>
					<span v-else>{{$t('system.submitting')}}</span>
				</el-button>
				<el-button :size="size" @click="closeForm">{{$t('system.cancel')}}</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { update, getFieldList } from '@/api/app/minus'

export default {
	name:'minusupdate',
	components: {
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		info: {
			type: Object,
		},
	},
	data(){
		return {
		    dialog:{
			},
			form: {
			   uid:'',
			   number:'',
			   remark:'',
			   status:0,
			   type:'',
			   create_time:'',
			   approved_by:'',
			   approve_time:'',
			   caller:'',
			},
			types:[],
			callers:[],
		    initial:{},        
			loading:false,
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
				getFieldList().then(res => {
					if(res.status == 200){
						this.types = res.data.types
						this.callers = res.data.callers
					}
				})
			}
		}
	},
	methods: {
		open(){
			this.form = this.info
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					update(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: this.$t('system.success'), type: 'success'})
							this.$emit('refresh_list')
							this.closeForm()
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss'
</style>
